DUAL SENSORS for a STAMP

by Jim Ubersetzig

This article was published in the March 1999 issue of the Robot Builder

 

Introduction

Have you ever wanted to add sensors to your robot - but weren't sure how to do it ? In this two-part article I will show you how to build a pair of inexpensive sensors which share a Basic Stamp 1 computer.

This stamp-based sensor system will include both Sonar and Infra Red (IR) sensors. The Sonar sensor measures the distance to an object, and the infra red (IR) sensor gives the probability of objects to the right, left or directly ahead of the robot. By operating both sensors off the same stamp computer - you save cost.

This month we will build the sonar system and get it working. Next month an article detailing the addition of an infra red sensor will be included.

 

Parts and Cost

Table 1 lists the parts you will need. Costs given are approximate. Other than the listed parts, you will need a PC to load the software in this article into the Basic Stamp. The stamp also uses the PC to display test results. If you use the remaining Basic Stamp pins to build a robot base to mount the sensor on, then the robot could operate without the PC.

Skills Required

You will need certain minimum skills to complete the device described in this article:

    Soldering, electronic grade

    Cutting plastic sheet

    Drilling holes

    Safety skills to avoid injuries.

Mechanical Construction

Begin by modifying the sharp IR module. It consists of a small circuit board enclosed in a metal box. Carefully bend the metal box and remove the circuit board. 

Compare the IR board with that shown in figure 1. There are three metal leads on one side and two metal leads with a plastic blob on the other side. Carefully cut off the plastic blob LEAVING the metal wires on the IR board. These wires need to be as long as possible.

The plastic blob you cut off is a photodiode, which detects infra red light. This is used in IR remote controls and the IR board is sensitive to 40KHz IR. We will substitute a 40KHz sonar transducer.

You will need to bend the leads on the sonar transducer closer together before soldering them to the two wires on the IR board. Be SURE to use the 255-400SR12 which is the receiver.

Note that one of the wires on the sonar transducer is welded to the metal can. This must solder to the IR board wire marked GND in the figure.

Now solder the group of three wire leads to the perfboard as shown in figure 2.

Figure 2 - Parts Layout

Note that the sonar transducer faces away from the perfboard. Next wrap the sonar transmitter with felt (except the end where the sound comes out). 

Bend the wire leads at an angle so that the transmitter will point in the same direction as the receiver. Solder to the perfboard with at least one inch between the transmitter and the receiver.

Electrical Construction

Now install the rest of the parts and wires, saving the Basic Stamp 1 for last. The parts placement guide (Figure 2) and the schematic diagram (Figure 3) should provide enough information for installing all of the electrical parts.

The author substituted a stamp carrier board ( $ 15.00 ) for the perfboard because it has a socket for the Basic Stamp 1 and also has clips for the 9 volt battery.  Using perforated board is less expensive.

Theory of Operation

The Sonar sensor operates by bouncing sound off objects. The transmitting element produces a brief burst of sound which is immediately detected by the receiver.

The receiver also detects the echo of sound bounced off the object being detected. By measuring the time between the transmitted sound and the received sound, the distance to the object can be determined.

The distance is reported as a number, which can be used by a robot to avoid running  into obstacles.

In the timing diagram (figure 4), time increases to the right, and higher voltage is up. This is what you would see on an oscilloscope if you triggered on P0 of the stamp.

So how does it work ? Signal P0 is driven by the Stamp computer to control a 555 timer integrated circuit. P0 holds the timer reset until the sonar is used.

Object - P0 is pulsed high long enough for the 555 to emit 25 cycles of 40KHz to the transmitter transducer, which emits the sound.

The transmitter transducer has a high impedance of about 100K ohms, so the 1M ohm adjustable trimmer allows a 10 to 1 range of adjustment for loudness of the emitted sound.

The transmitter’s internal arrangement is precisely made to resonate at 40KHz. In a way this is good, as the small electrical signal is greatly increased. But it is necessary to wrap the transmitter in felt (or other sound deadening material) to damp out the ringing which occurs after the electrical signal is no longer driving the transmitter.

The receiver is located close to the transmitter, so it detects the transmitted sound as well as the echo from any objects in the sound path.

Examine the receiver signal P1 carefully: normally the signal is logic high (near +5 volts) but when sound of the type used is detected the signal goes to logic low (near ground) for a while. This downward pulse occurs twice: once for the transmitted signal and  once for the received signal. Note that the first downward pulse continues after the transmitted sound ends. This is critical to the design - as it allows the Stamp's pulsin instruction to be used to measure the signal high period between transmit and receive.  The pulsin instruction returns a number that is bigger for objects that are farther away.

There are a couple of things to keep in mind when using this number:

 

1. Objects closer than 10 inches are not detected.

2. The number is about 12 counts per inch of distance.

3. If there is nothing to reflect the sound,    the number is zero.

Software

The following is the Basic Stamp 1 code to test your sonar:

' Software for the 40 KHz Sonar
' by Jim Ubersetzig
'
' Runs on the Basic Stamp 1              10 Jun 98
' P0        xmit modulation    high = xmit
' P1        rcvr signal        low = detect
' symbols
symbol range = w2
symbol x     = w3
symbol loop  = w4
dirs = %00000001     ' P0 is output, P1 is input
low 0
start:
for loop = 1 to 5
pulsout 0, 25 ' 10 cycles at 40 KHz
for x=1 to 60 :next x
next loop
pulsout 0, 25 ' 10 cycles at 40 KHz
pulsin 1,1,range
debug "range ",#range,cr ' in units of 1/12 inch, 0 for nothing
for x=1 to 60 :next    ' delay for reading display.
goto start
' End of the software

Get It Working ?

On your PC type stamp <enter> and the stamp development system will come up. If you don't have this file ( stamp.exe  approx. 15K bytes ), it's a free download from the parallax web site. It also comes with the developer's kit, along with the cable. If you don't have the cable, instructions for building one are on the web site.

On your PC you should see a blue screen. Type in the software, then ALT-S  to save the software in a file. Type in a suitable file name, then <enter>. Now ALT-Q to exit.  The software is saved on your PC.

 

To operate the sonar sensor: On the PC type stamp <enter>.

You'll see the blue screen again.  ALT-L will let you select the software you have previously saved. Once you see the software on the PC display, hook up the cable from your PC's com port to the stamp. NOTE that the cable can go two different ways on the stamp. Line up the marks ! Now ALT-R will start the software running. You should see a list of numbers on the computer screen. These are the distance numbers reported by the sonar sensor.

Place an object where the sensor should see it and the numbers should change. Experiment with different objects and different distances.

Troubleshooting

If things don't work as expected, there are several adjustments. First, check the software you typed in. Did you copy it exactly ?

If all the numbers are zero - the receiver is not working. Try adjusting the 10K ohm trim pot. You want 40 KHz at pin 3 of the 555. This can be measured with a frequency counter, some digital voltmeters have this built in. Alternately you can measure the period with a scope. The period for 40KHz is about 25 microseconds. If you need to  djust this, type in this single line software "HIGH

0"

If the sonar only detects objects that are very far away, the transmitter is ringing. The solution is to add more felt. Wrap it around the transmitter can. It the sensor is too sensitive ( detects when there is no object ), turn down the drive level to the transmitter. This is done by adjusting the 1M ohm trim pot.

The Future ?

Next month we will add an Infra Red (IR) sensor that reports probability numbers ( range 0 .. 10 ) for objects to the right, to the left, and directly ahead of the robot.